package net.yla.smartbus.module.ba.area.detachment;

import net.yla.smartbus.module.ba.area.dto.AreaDto;
import net.yla.smartbus.module.ba.area.dto.Point;
import net.yla.smartbus.module.ba.area.entity.BaPoints;
import net.yla.smartbus.module.ba.area.entity.BaRegionsDo;
import net.yla.smartbus.module.ba.area.service.PointsService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 默苍离
 * @date 2021/6/28 10:42
 * <p>
 * ******************************************
 * @annotation: 抽离的方法
 */
@Component
public class AreaDetachment {

    private final PointsService pointsService;

    public AreaDetachment(PointsService pointsService) {
        this.pointsService = pointsService;
    }

    /**
     * 区域do转dto
     *
     * @param area
     * @return
     */
    public AreaDto areaDoToTto(BaRegionsDo area) {
        AreaDto areaDto = new AreaDto();
        areaDto.setRegionId(area.getRegionId());
        areaDto.setAreaName(area.getName());
        areaDto.setRegionType(area.getRegionType());
        switch (area.getRegionType()) {
            case 1:
                areaDto.setRegionTypeName("限速区域");
                break;
            case 2:
                areaDto.setRegionTypeName("停车场");
                break;
            case 3:
                areaDto.setRegionTypeName("加油站充电区");
                break;
            case 4:
                areaDto.setRegionTypeName("禁止区域");
                break;
            case 5:
                areaDto.setRegionTypeName("出租车停靠点");
                break;
            default:
                areaDto.setShapeTypeName("---");
        }
        areaDto.setShapeType(area.getShapeType());
        switch (area.getShapeType()) {
            case 1:
                areaDto.setShapeTypeName("多边形");
                break;
            case 2:
                areaDto.setShapeTypeName("矩形");
                break;
            case 3:
                areaDto.setShapeTypeName("圆形");
                break;
            default:
                areaDto.setShapeTypeName("---");
        }
        areaDto.setDynamicValue(area.getValue());

        List<BaPoints> point = pointsService.getPoint(area.getRegionId());
        if (point != null && point.size() > 1) {
            areaDto.setRadius(point.get(0).getRadius());
            areaDto.setLatitude5(point.get(0).getLatitude5());
            areaDto.setLongitude5(point.get(0).getLongitude5());
            ArrayList<Point> points = new ArrayList<>();
            for (int i = 0; i < point.size(); i++) {
                BaPoints baPoints = point.get(i);
                Point point1 = new Point();
                point1.setLat(baPoints.getLatitude2());
                point1.setLng(baPoints.getLongitude2());

                points.add(point1);
            }
            areaDto.setPointsList(points);
        }

        return areaDto;
    }


}
